package com.newsmanagement.controller.backstage;

import com.newsmanagement.entity.ReturnedMessages;
import com.newsmanagement.service.IResourceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author xbr
 * 2017.12.04 11:24
 * 后台系统 资源管理
 */
@Controller
@RequestMapping("resourceBack")
public class ResourceBackstageController {

    @Autowired
    private IResourceService resourceService;

    /**
     * 添加资源
     * @param userId 操作人id
     * @param resourceName 资源名称
     * @param resourceInfo 资源内容
     * @return
     * 测试：http://localhost:8080/resourceBack/addResource?userId=1&resourceName=ziyuanmingcheng&resourceInfo=ziyuanneirong
     */
    @RequestMapping("addResource")
    @ResponseBody
    public ReturnedMessages addResource(
            @RequestParam(value = "userId") Integer userId ,
            @RequestParam(value = "resourceName") String resourceName ,
            @RequestParam(value = "resourceInfo") String resourceInfo
    ){

        return resourceService.addResource(userId ,resourceName ,resourceInfo);
    }


    /**
     * 修改资源
     * @param userId 操作人id
     * @param resourceId 资源id
     * @param resourceName 资源名称
     * @param resourceInfo 资源内容
     * @return
     * 测试：http://localhost:8080/resourceBack/updateResource?userId=2&resourceInfo=ziyuanneirong11&resourceName=ziyuanmingcheng11&resourceId=1
     */
    @RequestMapping("updateResource")
    @ResponseBody
    public ReturnedMessages updateResource(
            @RequestParam(value = "userId") Integer userId ,
            @RequestParam(value = "resourceId") Integer resourceId ,
            @RequestParam(value = "resourceName") String resourceName ,
            @RequestParam(value = "resourceInfo") String resourceInfo
    ){

        return resourceService.updateResource(userId , resourceId ,resourceName ,resourceInfo);
    }


    /**
     * 删除资源
     * @param userId 操作人id
     * @param resourceId 资源id
     * @return
     * 测试：http://localhost:8080/resourceBack/deleteResource?userId=4&resourceId=1
     */
    @RequestMapping("deleteResource")
    @ResponseBody
    public ReturnedMessages deleteResource(
            @RequestParam(value = "userId") Integer userId ,
            @RequestParam(value = "resourceId") Integer resourceId
    ){

        return resourceService.deleteResource(userId , resourceId);
    }

}
